/**
 * @param {string} sentence
 * @param {number} discount
 * @return {string}
 */
var discountPrices = function(sentence, discount) {
  const reg = /^\$(\d+)$/g;
  const strArr = sentence.split(' ');
  for(let i = 0; i < strArr.length; i++) {
    strArr[i] = strArr[i].replace(reg, function() {
      const price = (parseFloat(arguments[1]) - parseFloat(arguments[1]) * (discount / 100)).toFixed(2) + '';
      return '$' + price;
    });
  }
  return strArr.join(' ');
};
let sentence = "there are $1 $2 and 5$ candies in the shop", discount = 50;
console.log(discountPrices(sentence, discount));
sentence = "1 2 $3 4 $5 $6 7 8$ $9 $10$", discount = 100;
console.log(discountPrices(sentence, discount));
sentence = "ka3caz4837h6ada4 r1 $602", discount = 9;
console.log(discountPrices(sentence, discount));
sentence = "$2$3 $10 $100 $1 200 $33 33$ $$ $99 $99999 $9999999999", discount = 0;
console.log(discountPrices(sentence, discount));
sentence = "$2$3 $10 $100 $1 200 $33 33$ $$ $99 $99999 $9999999999", discount = 0;
